<?php

class M_info extends CI_Model{
	

	function __construct(){
		parent::__construct();
	}
	
	function create($judul,$isi,$tgl){
		$data = array(
		'judul' =>$judul,
		'isi' => $isi,
		'tgl' => $tgl
		);
		
		$this->db->insert('info', $data);
		if ($this->db->affected_rows() == 1) {
			return TRUE;
		}
		return FALSE;
	}
	
	function getTable($perPage = 0, $offset = 0) {
        $this->db->select('*');
		$this->db->order_by('id_info', 'DESC');
        $this->db->limit($perPage, $offset);
        $query = $this->db->get('info');

        return $query->result_array();
        
    }
	
	function getAllData(){
		$this->db->select('*');
		$this->db->order_by('id_info', 'DESC');
        $query = $this->db->get('info');
		
        if ($query->num_rows() > 0) {
            return $query->result_array();
        }
	}
	
	function getDataById($id){
		$this->db->select('*');
		$this->db->where('id_info', $id);
		$query = $this->db->get('info');
		
		if($query->num_rows() == 1){
			return $query->result_array();
		}
	}
	
	function update($id,$judul,$isi){
		$data = array(
		'judul' =>$judul,
		'isi' => $isi
		);
		$this->db->where('id_info', $id);
		$this->db->update('info', $data);
		
		if ($this->db->affected_rows() == 1) {

            return TRUE;
        }
        return FALSE;
	}
	
	function delete($id){
		$this->db->where('id_info', $id);
		$this->db->delete('info');
		if ($this->db->affected_rows() == 1) {

            return TRUE;
        }
        return FALSE;
	}

}